/* GUI CONVERTED from rcgetord.i (converter v1.76) Fri May  3 13:21:11 2002 */
/* rcgetord.i - Release Management Customer Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.17.1.5 $                                                      */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3    LAST MODIFIED: 09/30/92           BY: WUG *G462*          */
/* REVISION: 7.3    LAST MODIFIED: 05/24/93           BY: WUG *GB29*          */
/* REVISION: 7.3    LAST MODIFIED: 07/26/93           BY: WUG *GA72*          */
/* REVISION: 7.3    LAST MODIFIED: 08/13/93           BY: WUG *GE19*          */
/* REVISION: 7.3    LAST MODIFIED: 08/25/94           BY: dpm *GL50*          */
/* REVISION: 7.3    LAST MODIFIED: 10/21/94           BY: dpm *GN47*          */
/* REVISION: 7.3    LAST MODIFIED: 10/27/94           BY: ljm *GN70*          */
/* REVISION: 7.3    LAST MODIFIED: 10/31/94           BY: rxm *GN17*          */
/* REVISION: 7.5    LAST MODIFIED: 12/13/94           BY: mwd *J034*          */
/* REVISION: 8.5    LAST MODIFIED: 05/22/96           BY: jpm *J0N8*          */
/* REVISION: 8.5    LAST MODIFIED: 09/09/96           BY: dxk *J14T*          */
/* REVISION: 8.5    LAST MODIFIED: 10/15/96           BY: *G2GJ* Ajit Deodhar */
/* REVISION: 8.6    LAST MODIFIED: 05/12/97           BY: jpm *K0D1*          */
/* REVISION: 8.5    LAST MODIFIED: 06/05/97           BY: jpm *J1R8*          */
/* REVISION: 8.6    LAST MODIFIED: 12/15/97           BY: *K1DP* Niranjan R.  */
/* REVISION: 8.5    LAST MODIFIED: 03/09/98           BY: *J2G8* Jean Miller  */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98           BY: *K1Q4* Alfred Tan   */
/* REVISION: 9.1    LAST MODIFIED: 07/07/99           BY: *J3HR* Sachin Shinde*/
/* REVISION: 9.1    LAST MODIFIED: 03/24/00      BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00      BY: *N0KP* Mark Brown        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.17.1.4    BY: Jean Miller       DATE: 02/27/02  ECO: *N1BB*    */
/* $Revision: 1.17.1.5 $   BY: Katie Hilbert     DATE: 04/15/02  ECO: *P03J*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* GETS A SCHEDULED ORDER XREF RECORD (scx_ref) */
/* {1}="old" if the record has to exist
   {2}=command to execute within next/previous
   {3}=any non-blank value to enable site security check.(update programs              need site security whereas inquiry/report programs do not)
*/

define new shared variable global_order as character.
define new shared variable global_line as integer.

define variable so_db as character.
define variable l_desc1  like pt_desc1   no-undo.
define variable tmp-scx-shipfrom like scx_ref.scx_shipfrom no-undo.
define variable tmp-scx-shipto   like scx_ref.scx_shipto   no-undo.
define shared variable window_recid as recid.

recno = recid(scx_ref).

do with frame a:

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame a:handle).

   on leave of scx_shipfrom in frame a do:
      tmp-scx-shipfrom = input frame a scx_shipfrom.
           
      do on error undo, leave:
         run q-leave in global-drop-down-utilities.
      end.
      run q-set-window-recid in global-drop-down-utilities.
      if return-value = "error" then return no-apply.   
   end.

   on leave of scx_shipto in frame a do:
      tmp-scx-shipto = input frame a scx_shipto.
           
      do on error undo, leave:
         run q-leave in global-drop-down-utilities.
      end.
      run q-set-window-recid in global-drop-down-utilities.
      if return-value = "error" then return no-apply.   
   end.

   on leave of scx_part in frame a do:

           
      do on error undo, leave:
         run q-leave in global-drop-down-utilities.
      end.
      run q-set-window-recid in global-drop-down-utilities.   

      if window_recid <> ? then do:

         find first sod_det where recid(sod_det) = window_recid
         no-lock no-error.

         if available sod_det then do:

            find first scx_ref no-lock where (scx_type = 1 and
            scx_order = sod_nbr and scx_line = sod_line) no-error.

            if available scx_ref then do:

               find ad_mstr where ad_addr = scx_shipto no-lock no-error.

               display
                  scx_shipfrom
                  scx_shipto
                  ad_name  when (available ad_mstr)
                  scx_part
                  scx_po
                  scx_custref
                  scx_modelyr
                  scx_order
                  scx_line
               with frame a.

            end.

         end.

         window_recid = ?.

      end. /* if window_recid <> ? */

      if return-value = "ERROR" then return no-apply.

   end. /*on leave of scx_part */

   run get-input.

   if keyfunction(lastkey) = "end-error" then undo, leave.

   find scx_ref where scx_type = 1
                  and scx_shipfrom = input frame a scx_shipfrom
                  and scx_shipto   = input frame a scx_shipto
                  and scx_part     = input frame a scx_part
                  and scx_po       = input frame a scx_po
                  and scx_custref  = input frame a scx_custref
                  and scx_modelyr  = input frame a scx_modelyr
   no-lock no-error.

   if not available scx_ref then do:

      find scx_ref where scx_type = 1
                     and scx_order = input frame a scx_order
                     and scx_line = input frame a scx_line
      no-lock no-error.

   end.

   if "{1}" = "old" and not available scx_ref then do:
      /* Scheduled Order detail record does not exist */
      {pxmsg.i &MSGNUM=8104 &ERRORLEVEL=3}
      undo, retry.
   end.

   if available scx_ref then do:

      if "{1}" = "old"  and
         (input frame a scx_order  entered or
          input frame a scx_line   entered )
      then do:

         if (input frame a scx_line <>  0 and
             input frame a scx_line <> scx_line)
         or (input frame a scx_order <> "" and
             input frame a scx_order <> scx_order)
         then do:
            /* Scheduled Order detail record does not exist */
            {pxmsg.i &MSGNUM=8104 &ERRORLEVEL=3}
            undo, retry.
         end.

      end.

      find si_mstr where si_site = scx_shipfrom no-lock no-error.

      run check-site.

      find ad_mstr where ad_addr = scx_shipto no-lock no-error.
      find pt_mstr where pt_part = scx_part no-lock no-error.

      find sod_det where sod_nbr = scx_order
                     and sod_line = scx_line no-lock no-error.
      find so_mstr where so_nbr = sod_nbr no-lock .

      if available pt_mstr then
         l_desc1 = pt_desc1.
      else if available sod_det then
         l_desc1 = sod_desc.
      else
         l_desc1 = "".

      global_addr =  so_cust.

      run check-sched.

      /* MUST BE IN SAME DATABASE AS ORDER CREATED IN */
      so_db = trim(substring(so_conrep,15,20)).

      if so_db <> global_db then do:
         /* You must be in database # */
         {pxmsg.i &MSGNUM=8148 &ERRORLEVEL=3 &MSGARG1=so_db}
         undo, retry.
      end.

      display
         scx_shipfrom
         scx_shipto
         ad_name      when (available ad_mstr)
         scx_part
         pt_um        when (available pt_mstr)
         l_desc1    @ sod_desc
         sod_custpart when (available sod_det)
         scx_custref
         scx_modelyr
         sod_custpart when (available sod_det)
         scx_po
         scx_order
         scx_line.

      assign
         global_order = sod_nbr
         global_line = sod_line.

      {gpbrparm.i &browse=gplu544.p &parm=c-brparm1 &val="global_order"}
      {gpbrparm.i &browse=gplu544.p &parm=c-brparm2
                  &val="string(global_line)"}

   end.

end.

PROCEDURE check-site:
/* --------------------------------------------------------------------
  Purpose:     Check to see if Valid site and if user has access
  Parameters:  <none>
  Notes:
 ----------------------------------------------------------------------*/

   do on error undo, retry :
/*GUI*/ if global-beam-me-up then undo, leave.


      if not available si_mstr then do:
         /* SITE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=780 &ERRORLEVEL=3}
         return error.
      end.

      /* IF MAINTENANCE MODE THEN ENABLE SITE SECURITY */
      if "{3}" <> "" then do:
         {gprun.i ""gpsiver.p""
          "(input si_site, input recid(si_mstr), output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            /* USER DOES NOT HAVE ACCESS TO SITE */
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            return error.
         end. /* IF RETURN_INT = 0 */
      end. /* IF "{3}" <> "" */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* DO ON ERROR */

END PROCEDURE.

PROCEDURE check-sched:
/* --------------------------------------------------------------------
  Purpose:     Check to see if Valid scheduled order
  Parameters:  <none>
  Notes:
-----------------------------------------------------------------------*/

   do on error undo, retry :
/*GUI*/ if global-beam-me-up then undo, leave.


      if sod_det.sod_start_eff[1] > today or sod_end_eff[1] < today
      then do:
         /* Scheduled Order is no longer effective */
         {pxmsg.i &MSGNUM=8105 &ERRORLEVEL=2}
         return.
      end.

      if sod_cum_qty[1] >= sod_cum_qty[3]
      and sod_cum_qty[3] > 0
      then do:
         /* Cum Ship Qty >= Max Order Qty for order selected */
         {pxmsg.i &MSGNUM=8220 &ERRORLEVEL=2}
         return.
      end.

      if not sod_sched then do:
         /* Line item is not scheduled */
         {pxmsg.i &MSGNUM=6004 &ERRORLEVEL=3}
         return error.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


END PROCEDURE. /* check-sched */

PROCEDURE get-input:
/* ---------------------------------------------------------------------
  Purpose:    Prompt for order parameters, next-previous key processing
  Parameters: <none>
  Notes:
 -----------------------------------------------------------------------*/

   do on error undo, retry on endkey undo, leave with frame a :
/*GUI*/ if global-beam-me-up then undo, leave.


      prompt-for scx_shipfrom scx_shipto  scx_part  scx_po
                 scx_custref  scx_modelyr scx_order scx_line
      editing:

         assign
            global_order = input frame a scx_order
            global_line = input frame a scx_line.

         {gpbrparm.i &browse=gplu544.p &parm=c-brparm1 &val="global_order"}
         {gpbrparm.i &browse=gplu544.p &parm=c-brparm2
                     &val="string(global_line)"}

         if frame-field = "scx_shipfrom" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1"
               scx_shipfrom "input frame a scx_shipfrom"}
         end.

         else
         if frame-field = "scx_shipto" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
              and scx_shipfrom = input frame a scx_shipfrom"
              scx_shipto "input frame a scx_shipto"}
         end.

         else
         if frame-field = "scx_part" then do:

            if tmp-scx-shipfrom = "" and tmp-scx-shipto = "" then do:

               {mfnp05.i sod_det sod_part
                  "sod_sched" sod_part "input frame a scx_part"}

               if recno <> ? then do:

                  find scx_ref where scx_order = sod_nbr
                     and scx_line = sod_line
                     and scx_type = 1
                  no-lock no-error.

                  if not available scx_ref then do:
                     recno = ?.
                     display
                        "" @ scx_po
                        sod_part @ scx_part
                        "" @ scx_shipfrom
                        "" @ scx_shipto
                        "" @ scx_order
                        "" @ ad_name
                        "" @ sod_desc
                        "" @ scx_custref
                        "" @ scx_modelyr.
                  end.

               end.

            end.

            else do:
               {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
                  and scx_shipfrom = input frame a scx_shipfrom
                  and scx_shipto = input frame a scx_shipto"
                      scx_part "input frame a scx_part"}
            end.

         end.

         else
         if frame-field = "scx_po" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
               and scx_shipfrom = input frame a scx_shipfrom
               and scx_shipto = input frame a scx_shipto
               and scx_part = input frame a scx_part"
                   scx_po "input frame a scx_po"}
         end.

         else
         if frame-field = "scx_custref" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1 and
                      scx_shipfrom = input frame a scx_shipfrom and
                      scx_shipto = input frame a scx_shipto and
                      scx_part = input frame a scx_part and
                      scx_po = input frame a scx_po"
                      scx_custref "input frame a scx_custref"}
         end.

         else
         if frame-field = "scx_modelyr" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1 and
                      scx_shipfrom = input frame a scx_shipfrom and
                      scx_shipto = input frame a scx_shipto and
                      scx_part = input frame a scx_part and
                      scx_po = input frame a scx_po and
                      scx_custref = input frame a scx_custref"
                      scx_modelyr "input frame a scx_modelyr"}
         end.

         else
         if frame-field = "scx_order" then do:
            {mfnp05.i scx_ref scx_order "scx_type = 1"
             scx_order "input frame a scx_order"}
         end.

         else
         if frame-field = "scx_line" then do:
            {mfnp05.i scx_ref scx_order
               "scx_type = 1 and scx_order = input frame a scx_order"
               scx_line "input frame a scx_line"}
         end.

         else do:
            status input.
            readkey.
            apply lastkey.
         end.

         if recno <> ? then do:
            find si_mstr where si_site = scx_shipfrom
            no-lock no-error.

            find ad_mstr where ad_addr = scx_shipto no-lock no-error.
            find pt_mstr where pt_part = scx_part no-lock no-error.

            find sod_det where sod_nbr = scx_order
                           and sod_line = scx_line
            no-lock no-error.

            if available pt_mstr then
               l_desc1 = pt_desc1.
            else if available sod_det then
               l_desc1 = sod_desc.
            else
               l_desc1 = "".

            display
               scx_shipfrom
               scx_shipto
               ad_name       when (available ad_mstr)
               scx_part
               pt_um         when (available pt_mstr)
               l_desc1    @ sod_desc
               sod_custpart  when (available sod_det)
               scx_custref
               scx_modelyr
               scx_po
               scx_order
               scx_line.

            {2}

         end. /* if recno <> ?  */

      end. /* prompt-for scx_shipfrom .. */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* do on error undo, retry .. */

END PROCEDURE. /* get-input */
